/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package job.manager.client.mb;

import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.model.SelectItem;
import job.manager.db.ec.ProfilesEB;
import job.manager.db.sb.ProfileRemote;



/**
 *
 * @author Administrator
 */

public class ProfileMB implements ActionListener{
    @EJB
    private ProfileRemote profileBean;

    
    private ProfilesEB profile;
    private boolean isEmployee;
    private String fname;
    private String lname;
    private String address1;
    private String address2;
    private String postcode;
    private String city;
    private String country;
    private String phone1;
    private String phone2;
    private String email;
    private String comment;
    private String number;

    private Collection<ProfilesEB> profileList;
    /** Creates a new instance of ProfileMB */
    public ProfileMB() {
    }

    @PostConstruct
    public void onInit() {
        this.profile = null;
        this.isEmployee = true;
        this.fname = "";
        this.lname = "";
        this.address1 = "";
        this.address2 = "";
        this.postcode = "";
        this.city = "";
        this.country = "";
        this.phone1 = "";
        this.phone2 = "";
        this.email = "";
        this.comment = "";
    }

    private void loadProfiles() {
        this.profileList = profileBean.getAllProfiles();
    }

     public ArrayList<SelectItem> getProfiles() {
         if( this.profileList == null)
             loadProfiles();
        ArrayList<SelectItem> itemList = new ArrayList<SelectItem>();

        ArrayList<ProfilesEB> profiles = new ArrayList(this.profileList);

        for (ProfilesEB prof : profiles) {
            SelectItem a = new SelectItem();
            a.setLabel(prof.getName1() + " " +prof.getName2());
            a.setValue(prof.getId().toString());
            itemList.add(a);
        }
        return itemList;
    }

    public boolean isIsEmployee() {
        return isEmployee;
    }

    public void setIsEmployee(boolean isEmployee) {
        this.isEmployee = isEmployee;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getPhone1() {
        return phone1;
    }

    public void setPhone1(String phone1) {
        this.phone1 = phone1;
    }

    public String getPhone2() {
        return phone2;
    }

    public void setPhone2(String phone2) {
        this.phone2 = phone2;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

   

    public void processAction(ActionEvent event) throws AbortProcessingException {
        this.profile = new ProfilesEB();
        profile.setIsCustomer(!isEmployee);
        profile.setIsEmployee(isEmployee);
        profile.setComment(comment);
        profile.setName1(fname);
        profile.setName2(lname);
        profile.setNumber(number); 
    }

    

}
